import "./App.css";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import ROUTER_CLOCK from "./router/index";
import React, { useEffect } from "react";
import { useDispatch } from "react-redux";

const App = () => {
  const dispatch = useDispatch();
  const searchParams = new URLSearchParams(window.location.search);
  const paramsObject = {};
  for (const [key, value] of searchParams.entries()) {
    paramsObject[key] = value;
  }
  const increment = () => {
    dispatch({ type: "INSERT_DATA", payload: paramsObject });
  };

  // 白名单路由
  const whiteList = [
    "/ctManage",
    "/custmerManage",
    "/custmerSerive",
    "/storeNumber",
    "*",
  ];

  useEffect(() => {
    increment();
  }, []);

  return (
    <>
      <React.Suspense>
        <Router basename="/pc">
          <Routes>
            {ROUTER_CLOCK?.map((item) => {
              if (whiteList.includes(item.path)) {
                return <Route path={item.path} element={<item.element />} />;
              } else {
                return <></>;
              }
            })}
          </Routes>
        </Router>
      </React.Suspense>
    </>
  );
};

export default App;
